var layerId;
$(function(){
	$("#search-button").click(function(){
		var keyword=$("input[name='keyword']").val();
		var style=$("select[name='style']").val();
		var scene =$("select[name='scene']").val();
		var isRecommend =$("select[name='isRecommend']").val();
		var url=basePath+"/group/getGroupGoodsList.shtml?pageNo=1&keyword="+keyword
		+"&scene=" +scene + "&style="+style+"&isRecommend="+isRecommend;
		window.location.href=url;
	})
	$("#save-button").click(function(){
		var goodsChecked=$(".goods-checkbox:checked");
		var chooseType=init.chooseType;
		if(goodsChecked.length==0){
			layer.msg("请选择组货！");
			return false;
		}
		var goodsArray=new Array();
		if(chooseType == 'one'){
			var groupId=$(goodsChecked[0]).val();
			var scene=$(goodsChecked[0]).attr("data-scene");
			var coverImage=$(goodsChecked[0]).attr("data-image");
			var style=$(goodsChecked[0]).attr("data-style");
			var customer=$(goodsChecked[0]).attr("data-customer");
			var goods={
					"id":groupId,
					"coverImage":coverImage,
					"style":style,
					"scene":scene,
					"customer":customer
			}
			goodsArray.push(goods);
		}else{
			for(i=0;i<goodsChecked.length;i++){
				var groupId=$(goodsChecked[i]).val();
				var scene=$(goodsChecked[i]).attr("data-scene");
				var coverImage=$(goodsChecked[i]).attr("data-image");
				var style=$(goodsChecked[i]).attr("data-style");
				var customer=$(goodsChecked[i]).attr("data-customer");
				var goods={
						"id":groupId,
						"coverImage":coverImage,
						"style":style,
						"scene":scene,
						"customer":customer
				}
				goodsArray.push(goods);
			}
		}
		parent.closeGroupLayer(1,goodsArray);
	})
	
	$("#reset-button").click(function(){
		$("input[name='keyword']").val("");
	});
	$("#add-button").click(function(){
		openEdit(0);
	});
})
function openEdit(groupId){
	layerId=layer.open({
		title: "组货信息编辑",
		area: ['1200px','850px'],
		fix:true,
		type: 2,
		maxmin:true,
		content: basePath+'/group/edit.shtml?groupId='+groupId
	});
}
function closeGroupGoodsLayer(){
	if(layerId>0)
		layer.close(layerId);
	self.location.reload(true); 
}
function deleteGroup(groupId){
	if(confirm("确定删除？")){
	 $.ajax({
  		 url:basePath+"/group/deleteGroupGoods.shtml?groupId="+groupId,  
  		 type:"get",
  		 dataType:"JSON",
  		 success:function(data){
  			 if(data.code=="000000"){
  				layer.msg("操作成功");
  				setTimeout(function(){    
					self.location.reload(true);
				}, 1000);
  			 }else{
  				 layer.msg(data.msg);
  			 }
  		 },error:function(data){
  		 }
  	 });
	}
}

function fanye(pageNo){
	var keyword=$("input[name='keyword']").val();
	var style=$("select[name='style']").val();
	var scene =$("select[name='scene']").val();
	var url=basePath+"/group/getGroupGoodsList.shtml?pageNo="+pageNo+"&keyword="+init.keyword
	+"&scene=" +init.scene + "&style="+init.style+"&isRecommend="+init.isRecommend;
	window.location.href=url;
}